<!DOCTYPE html>
<html lang="en" xmlns:v-on="http://www.w3.org/1999/xhtml"
      xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>附件编辑</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-store, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta http-equiv="expires" content="-1">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/dist/img/icon.png" type="image/x-icon">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="/dist/plugins/bootstrap/css/bootstrap.min.css">
    <!--字体-->
    <link rel="stylesheet" href="/dist/css/font-awesome.min.css">
    <!--图标-->
    <link rel="stylesheet" href="/dist/css/ionicons.min.css">
    <!--插件样式-->
    <!--OA主样式-->
    <link rel="stylesheet" href="/dist/css/OA.min.css?t=86e2297f1">
    <link rel="stylesheet" href="/dist/css/skins/OA-skins.min.css?t=222aea35">
    <link rel="stylesheet" href="/dist/plugins/webuploader-0.1.5/webuploader.css">
    <link rel="stylesheet" href="//at.alicdn.com/t/font_855021_84xsjuczn2a.css">

    <style type="text/css">
        .layout{
            text-align: center;
            padding: 0 10px;
        }
        .layout table{
            width: 100%;
        }

        .layout table td{
           border:  1px solid #cbcbcd;
        }

        .layout table .left{
            width: 140px;
            height: 30px;
            background-color: #f5f5f5;
        }
        .layout table .center{
            text-align: left;
        }
        .layout table .center textarea{
            outline: none;
            border: 0;
            resize: none;
            height: 100px;
            width: 100%;
        }
        .layout table .right{
            width: 20%;
        }
       
        .webuploader-pick {
            background: url(/dist/img/fjT1.png) no-repeat 5px center;
            display: block;
            padding: 0 4px;
            height: 22px;
            line-height: 22px;
            padding-left: 15px;
            margin: 0 auto;
            width: 70px;
            border-radius: 4px;
            color: #2a8cec;
        }
        .webuploader-pick-hover {
            color: #fff !important;
            background: url(/dist/img/fjT2.png) no-repeat 5px center;
            background-color: #0F6099;

        }
    </style>
</head>
<body>
        <iframe id="ifAttach" style="display:none"></iframe>
<div class="layout" id="app">
    <table>
        <tr>
            <td class="left">附件</td>
            <td class="center" :colspan="enableEdit?'1':'2'">
                <div>
                    <div v-for="(attach,i) in detailParm.attaches" class="fj-tanzhongStyle">
                        <b :class="fjStyle(attach.name)"></b>
                        <div class="name" v-if="attach.name" :title="attach.name">
                            {{attach.name}}
                        </div>
                        <div class="down">
                            <a href="javascript:void(0)" class="nui-txt-link" @click="download(attach.url,attach.name)">下载</a>
                        </div>
                        <div class="del" v-show="enableEdit">
                            <a href="javascript:void(0)" class="nui-txt-link" @click="deleteFile(i)">删除</a>
                        </div>
                        <!--<div class="info"><span class="nui-txt-suc">上传完成</span></div>-->
                    </div>
                </div>
            </td>
            <td class="right" v-show="enableEdit">
                <div id="divUpload" >添加附件</div>
            </td>
        </tr>
        <tr>
            <td class="left">备注</td>
            <td class="center" colspan="2">
                <textarea id='beizhu' v-model="detailParm.remarks" :value="detailParm.remarks"></textarea>
            </td>
        </tr>
    </table>
    <div v-show="enableEdit" class="south" style="height:50px;line-height:50px;text-align:center;">
        <input type="button" value="保存" class="btn oaBtn btn-sm" @click="save()"/>
    </div>
</div>
<script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
<!--插件JS-->
<script src="https://file.ggxqce.com/web/bootstrap.min.js"></script>
<!--框架已定义 JS-->
<script src="/dist/js/app_iframe.js?t=8e743a31"></script>
<!--oa自定义  JS-->
<script src="/dist/js/oa.js?t=54c6b89c"></script>
<script src="https://file.ggxqce.com/web/vue.min.js"></script>
<script src="/dist/plugins/webuploader-0.1.5/webuploader.min.js"></script>
<script type="text/javascript">
    var api = frameElement.api, W = api.opener;
    var app = new Vue({
        el: "#app",
        data: {
            returnFlag:false,
            currentUser: getCurrentUser(),
            detailParm:{
                id:"",
                remarks:"",
                attaches: [] //附件
            },
            uploader: null,
            enableEdit:false,
        },
        methods: {
            refresh: function () {
                var that = this;
                $.wyui.postMethod(urlConfig.pm.projectTrack.getProjectAttaches, {
                    id:that.detailParm.id
                }, function (data) {
                   that.detailParm.attaches = data.attaches;
                   that.detailParm.remarks = data.remark;
                   var personList = data.personList;
                   data.personList.forEach(function(item){
                        if(item.PRO_PRINCIPAL == currentUser.id)
                            that.enableEdit =true;
                   });
                });
            },
            initUpload:function(){
                var that = this;
                this.uploader = WebUploader.create({
                    // 选完文件后，是否自动上传。
                    auto: true,
                    // swf文件路径
                    swf: "/statics/plugin/webuploader-0.1.5/Uploader.swf",
                    // 文件接收服务端。
                    server: server.ip +"/attach/uploadFile.json",
                    // 选择文件的按钮。可选。
                    // 内部根据当前运行是创建，可能是input元素，也可能是flash.
                    pick: '#divUpload',
                    duplicate: true
                });
                this.uploader.on("uploadStart", function () {
                    $("#progress").show();
                });
                this.uploader.on("uploadComplete", function () {
                    $("#progress").hide();
                });
                // 文件上传成功，给item添加成功class, 用样式标记上传成功。
                this.uploader.on('uploadSuccess', function (file, response) {
                    if (response._raw == "文件上传出错！") {
                        alert("文件上传出错！");
                    } else {
                        that.detailParm.attaches.push({
                            id: response.id,
                            name: response.name,
                            url: response.url
                        });
                    }
                });
                // 文件上传失败，显示上传出错。
                this.uploader.on('uploadError', function (file) {
                    alert("上传失败！");
                });
            },
            fjStyle: function (fjName) {
                if (fjName) {
                    var type = fjName.substring(fjName.lastIndexOf('.') + 1);
                    return 'img fj-' + type
                }
                return 'img'
            },
            download: function (attachId, fileName) {
                downloadFile(attachId,fileName)
                return false;
            },
            deleteFile: function (i) {
                if (window.confirm("确定要删除该附件吗?")) {
                    this.detailParm.attaches.splice(i, 1);
                }
            },
            save:function(){
                $.wyui.postMethod(urlConfig.pm.projectTrack.updateAttaches, trimRN(this.detailParm), function (data) {
                    parent.app.refresh();
                    api.close();
                });
            }
        },
        mounted: function () {
            $("#beizhu").focus();
            this.detailParm.id = $.wyui.page.urlParams.projectId;
            this.initUpload();
            this.refresh();
        }
    });
</script>
<script type="text/javascript">
$(function(){

});
</script>
</body>
</html>